package com.zf.shuashua.ui.popup;

import android.app.Activity;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.CenterPopupView;
import com.zf.shuashua.R;

/**
 * 通用弹框
 */
public class CommonNoAdPopup extends CenterPopupView {

    private TextView tvSum, tvTitle, btnTitle, tvUnit, tvbTitle;
    private ImageView imgClose;
    private String title, subTitle, value, uiType;
    private OnPopupListener mListener;

    public CommonNoAdPopup(@NonNull Activity context, String title, String subTitle, String value, String uiType) {
        super(context);
        this.title = title;
        this.subTitle = subTitle;
        this.value = value;
        this.uiType = uiType;
    }

    public void setPopupListener(OnPopupListener listener) {
        this.mListener = listener;
    }

    public void close() {
        dismiss();
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.common_noad_popup;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        setupView();
        setupData();
    }

    private void setupView() {
        tvTitle = findViewById(R.id.tvTitle);
        tvSum = findViewById(R.id.tvSum);
        btnTitle = findViewById(R.id.btTitle);
        tvUnit = findViewById(R.id.tvUnit);
        imgClose = findViewById(R.id.img_close);
        tvbTitle = findViewById(R.id.tvbTitle);
        btnTitle.setOnClickListener(v -> {
            if (mListener != null) {
                mListener.onNext();
            }
        });
        imgClose.setOnClickListener(v -> {
            dismiss();
            if (mListener != null) {
                mListener.onClose();
            }
        });
    }

    private void setupData() {
        String unit = "新客专享礼包".equals(title) || "领取成功!".equals(title) ? "元" : "金豆";

        tvUnit.setText(unit);
        tvTitle.setText(title);
        tvSum.setText(value);
        if ("0".equals(uiType)) {
            btnTitle.setVisibility(VISIBLE);
            tvbTitle.setVisibility(GONE);
            btnTitle.setText(subTitle);
        } else {
            tvbTitle.setVisibility(VISIBLE);
            btnTitle.setVisibility(GONE);
            tvbTitle.setText(subTitle);
        }
    }

}

